package com.ocom.srvpaccess.zyutils;

import com.ocom.common.utils.AES;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SignUtil {
	private static final Logger logger = LoggerFactory.getLogger(SignUtil.class);
	static public String getSignValue(String siteToken,Long timeStamp) {
		String sign1 = siteToken+"_"+timeStamp;
		logger.debug("sign1:"+sign1);
		String key = MD5Util.GetMD5Code(sign1);
		logger.debug("key:"+key);
		String cipherText = SM4Util.encryptEcb(key, sign1);
		logger.debug("cipherText:"+cipherText);
		String signValue = MD5Util.GetMD5Code(cipherText);
		logger.debug("signValue:"+signValue);
		return signValue;
	}
	
	static public String getSignValueV2(String siteToken,Long timeStamp) throws Exception {
		
		String sign1 = siteToken+"_"+timeStamp;
		
		logger.debug("sign1:"+sign1);
		
		String md5 = MD5Util.GetMD5Code(sign1);
		
		String key = md5.substring(0,16);
		
		String cipherText = AES.encrypt(sign1, key);
		
		logger.debug("cipherText:"+cipherText);
		
		String signValue = MD5Util.GetMD5Code(cipherText);
		
		logger.debug("signValue:"+signValue);
		return signValue;
	}
}
